package com.heima.article.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.wemedia.dtos.WmCommentApplyDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;
//dto.getBeginDate(),dto.getEndDate()
// 最大时间
//private String beginDate;
//// 最小时间
//private  String endDate;
////作者Id
//private  Long  authorId;
public interface ApArticleMapper extends BaseMapper<ApArticle> {
    List<ApArticle> loadArticles(@Param("dto") ArticleHomeDto dto,@Param("type") int type);

    List<ApArticle> findArticleListByLast5days(@Param("lastDay") Date last5Day);

        @Select("SELECT\n" +
                "\tapt.*,ap_article_config.is_comment\n" +
                "FROM\n" +
                "\tap_article_config\n" +
                "\tINNER JOIN ( SELECT * FROM ap_article WHERE ap_article.author_id = #{dto.authorId} " +
                "AND publish_time BETWEEN #{dto.beginDate} AND #{dto.endDate}" +
                " GROUP BY id ) AS apt ON apt.id = ap_article_config.article_id\n")
      List<ApArticle>  findArticlePage(@Param("dto") WmCommentApplyDto dto);


        @Select("SELECT\n" +
                "\tapt.*,ap_article_config.is_comment\n" +
                "FROM\n" +
                "\tap_article_config\n" +
                "\tINNER JOIN ( SELECT * FROM ap_article WHERE ap_article.author_id = #{dto.authorId} " +
                "AND publish_time BETWEEN #{dto.beginDate} AND #{dto.endDate}" +
                " GROUP BY id ) AS apt ON apt.id = ap_article_config.article_id\n")
        Page<ApArticle> findArticlePage1( Page page, @Param("dto") WmCommentApplyDto dto);

        @Select("SELECT COUNT(*) FROM ap_article")
        Integer querySize();

        //@Select("select * from music_info limit #{index},#{num}")
        //    public List<MusicInfo> queryByThread(@Param(value = "index")int index, @Param(value = "num")int num);
        @Select("SELECT * FROM ap_article LIMIT #{index},#{num}")
        List<ApArticle> limitApArticle(@Param(value = "index")int index, @Param(value = "num")int num);

}
